package cn.edu.zafu.bigdata.lb;
import java.util.Scanner;
/**
 * @author LiuBo
 * 定义自定义异常类InvalidAgeException
 */
class InvalidAgeException extends Exception {
    public InvalidAgeException(String message) {
        super(message);
    }
}
class AgeChecker {
    public static void checkAge(int age) throws InvalidAgeException {
        if (age < 18) {
            throw new InvalidAgeException("年龄不能小于18岁。");
        }
        System.out.println("年龄有效。");
    }
    public static void main(String[] args) {

        try (Scanner scanner = new Scanner(System.in)) {
            System.out.println("请输入您的年龄：");
            int age = scanner.nextInt();
            checkAge(age);
        } catch (InvalidAgeException e) {
            System.out.println("发生异常：" + e.getMessage());
        } catch (Exception e) {
            System.out.println("输入无效，请输入一个有效的数字。");
        }
    }
}